package com.dangdi.show.util;

import com.gexin.fastjson.JSON;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import sun.misc.IOUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;

public class WechatApiUtil {

    public static String getOpenId(String code) throws IOException {
        Map<String, Object> response = HttpClientUtil.HttoGet("https://api.weixin.qq.com/sns/jscode2session?appid=wx891e0d5eb52729aa&secret=ebb371688707c18d778eb98070a28924&js_code=" + code + "&grant_type=authorization_code");
//        System.out.println(response);
//        System.out.println("请求已发送");
//        HttpEntity entity=response.getEntity();
////        System.out.println(response.getStatusLine().getStatusCode());
////        System.out.println(entity.getContent().read());
//        System.out.println( "内容="+EntityUtils.toString(entity));
//        System.out.println("获取参数");
//        String string=EntityUtils.toString(entity,"UTF-8");
////        System.out.println(entity.getContentLength());
//        System.out.println("应该拿到了="+string);
//        System.out.println(string);
        String openID = JSON.parseObject(response.get("entity").toString()).get("openid").toString();
        return openID;
    }

}
